package com.shsxt.controller;

import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.hamcrest.core.SubstringMatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.shsxt.dao.AuntDao;
import com.shsxt.dao.IUserinfoDao;
import com.shsxt.dao.OrderDao;
import com.shsxt.dao.WodeDao;
import com.shsxt.dao.YuyueDao;
import com.shsxt.model.KOrder;
import com.shsxt.model.Notified;
import com.shsxt.model.UserInfo;
import com.shsxt.service.ControllService;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
@Component
public class Test  {
	@Autowired
	private static YuyueDao yuyueDao;
	@Autowired
	private static IUserinfoDao dao;
	@Autowired
	private static OrderDao orderDao;
	@Autowired
	private static  WodeDao wodeDao;
	@Autowired
	private static   AuntDao auntDao;
	    public static void main(String[] args) throws Exception {
	    	Float a=0f;
	    	System.out.println(a==0);
	    }
	    
	    static   String  test14   () throws InterruptedException, ParseException, APIConnectionException, APIRequestException{
			String fileName = "123456";

	    	return fileName.substring(fileName.length()-4, fileName.length());

	   }
	    static   void test13   () throws InterruptedException, ParseException, APIConnectionException, APIRequestException{
	    	Map<String,Object> param=new HashMap<String,Object>();
			param.put("type", "用户");
			param.put("detailType", "订单通知");
			param.put("notifiedContent", "您的[]订单现已经完成!");
			param.put("notifiedTime",new Date());
			param.put("phoneNumber", "15356506227");

			auntDao.createNotifiedMessage(param);

	   }
	   static   void test1() throws ParseException{
	    	  System.out.println((new Date().getTime()-new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2017-04-19 16:17:11").getTime()));
	    System.out.println(new Date().getTime());
	    System.out.println(60*60*24*1000);

	    System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2017-04-19 11:11:11").getTime());

	   }
	   public static int test2(String day) throws ParseException{
	    	
		   SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
		   Date date = null;
		    date = format.parse(day);
		    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
		    return ("10:00".length());
	
	    	}
	   static String test3(){
		   SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd ");//设置日期格式
		   return (df.format(new Date()));
	   }
	   static String test4() throws ParseException{
		   SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
		   Date date = null;
		    date = format.parse("2017年3月3日");
		    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd ");//设置日期格式
		    return (df.format(date));
	   }
	   static String test5() throws ParseException{
		   String orderNumber=String.valueOf(System.currentTimeMillis());
		    return orderNumber;
	   }
	   static String test6() throws ParseException{
		   SimpleDateFormat sp=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		    return sp.format(new Date());
	   }
	   static PKCS8EncodedKeySpec test7() throws ParseException{
		   byte[] decode = Base64.decode("MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANjVKl6p3PXKwxJbjUAl+xFvTTUiRjechQ5Ci8b089toOp8Q8zKWQl+RJY11zYp+wmwcZxfmrdKjx0fjEIDEbU9M/2ljdIo1FRPkofujYd9WQK18XDv0iyTmd7XKpnCLL73QTNfsJweArUd/utNglXnzBm1X6Y77wML0z2mfA7PBAgMBAAECgYBIveqC63VnN+iNZg1S8eryhGZgZukriuTQTd7alh6hAqx35JXR6LrHmMgCVvznc3MCFd04FXlG6w7VvQUyTbNlgwOXMz3k5SLSktxXCkTbQMIOYmW9lE+HJuxQS2JrTziP1evqmiGC/Zt9anwfKjFW+bYQSvVQEc2NTroFSXqvgQJBAPNS+7jiPYeFWzrHsq5vGCx+JxGoXAiJmBuaZPzurkW3hEIlzfSbjSL7ZdQAjEEMKbM4wqsoKvuMUB5VOGYtockCQQDkIOMMk3ZZxq7u19FSVSZv3QlJnA1DHKO/q196buhH5J21mr+n5m0UPYZoPueMJMR9CZvaH8lP2kogv8Z6TD45AkEAhDsBfty78UzgYhYqHS9UZMF9u9PRh/Y2SjHiVa3j2RE897GRti9eSLd0A/z0O1k/xBzBdcATc7Yxx/op9yUvOQJBAILY8iIGer2nnjLUivVkbbV/3JHh9iFmTe3kB9Gbx5Nk56iAaCmPm0UevPcSDZFujV0Co+gKj1dD53y9QsRm8tECQDvb1I9S4i4flckDl1p7tLT33ASFw3b+3fmZELUt+wtXYfHqeIje9OUCrGfkSql63PgcRglQ+YKVR1l0kjq5unI=");
		   PKCS8EncodedKeySpec priPKCS8   = new PKCS8EncodedKeySpec(decode );
		   return priPKCS8;
	   }
	    static PrivateKey test8() throws Exception {

		      byte[] keyBytes;
		      
		      keyBytes = Base64.decode("CMDMYTCMDMYT554200779");
		      
		      PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
		      
		      KeyFactory keyFactory = KeyFactory.getInstance("RSA");
		      
		      PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
		      
		      return privateKey;
		   }
	    public static String test9(String xxx,String weekTimes,String weeks)  throws Exception {
	    		String a=xxx;
	    		int b=Integer.valueOf(weeks);
	    		String c=weekTimes;
    			String[] days=a.split(";");
    			String daystr="";
    			String slotstr="";
    			String circle="";
    			
    			Date date=new Date();
			     Calendar   calendar   =   new   GregorianCalendar(); 
    			SimpleDateFormat sp=new SimpleDateFormat("EEEE");
    			SimpleDateFormat to=new SimpleDateFormat("yyyy年MM月dd日");
    			String week=sp.format(date);
    			int addday=0;
    			//获取第一次服务的日期
    			if(week.equals("星期一")){
        				addday=6;
    			}else if(week.equals("星期二")){
    				
    				addday=5;
    			}else if(week.equals("星期三")){
    				addday=4;
    			}else if(week.equals("星期四")){
    				addday=3;
    			}else if(week.equals("星期五")){
    				addday=2;
    			}else if(week.equals("星期六")){
    				addday=1;
    			}else if(week.equals("星期日")){
    				addday=0;
    			}
    			//按照服务周数每周+一天 获取接下来的年月日
	    		for(int y=0;y<b;y++){
	    			for(int i=0;days.length>i;i++){
	    				if(days[i].substring(0, 2).equals("周一")){
	    				     calendar.setTime(date); 
	    				   //两周一次
	    		    			if(weekTimes.equals("两周一次")){
		   	    				     calendar.add(calendar.DATE,addday+1+y*14);//把日期往后增加一天.整数往后推,负数往前移动 
	    		    			}else{
	   	    				     calendar.add(calendar.DATE,addday+1+y*7);//把日期往后增加一天.整数往后推,负数往前移动 

	    		    			}
	    				    Date date1=calendar.getTime(); 
		    				     daystr=daystr+ to.format(date1)+",";
		    				     slotstr=slotstr+days[i].substring(2, days[i].length())+",";
	    				}else if(days[i].substring(0, 2).equals("周二")){
	    					calendar.setTime(date); 
	    					if(weekTimes.equals("两周一次")){
	   	    				     calendar.add(calendar.DATE,addday+2+y*14);//把日期往后增加一天.整数往后推,负数往前移动 
	    					}else{
  	    				     calendar.add(calendar.DATE,addday+2+y*7);//把日期往后增加一天.整数往后推,负数往前移动 
	    					}	    
	    					Date date1=calendar.getTime(); 
		    				     daystr=daystr+ to.format(date1)+",";
		    				     slotstr=slotstr+days[i].substring(2, days[i].length())+",";
	    				}else if(days[i].substring(0, 2).equals("周三")){
	    					calendar.setTime(date); 
	    					if(weekTimes.equals("两周一次")){
	   	    				     calendar.add(calendar.DATE,addday+3+y*14);//把日期往后增加一天.整数往后推,负数往前移动 
	    					}else{
 	    				     calendar.add(calendar.DATE,addday+3+y*7);//把日期往后增加一天.整数往后推,负数往前移动 
	    					}	
	    				    Date date1=calendar.getTime(); 
		    				     daystr=daystr+ to.format(date1)+",";
		    				     slotstr=slotstr+days[i].substring(2, days[i].length())+",";
	    				}else if(days[i].substring(0, 2).equals("周四")){
	    					calendar.setTime(date); 
	    					if(weekTimes.equals("两周一次")){
	   	    				     calendar.add(calendar.DATE,addday+4+y*14);//把日期往后增加一天.整数往后推,负数往前移动 
	    					}else{
 	    				     calendar.add(calendar.DATE,addday+4+y*7);//把日期往后增加一天.整数往后推,负数往前移动 
	    					}	
	    				     Date date1=calendar.getTime(); 
		    				     daystr=daystr+ to.format(date1)+",";
		    				     slotstr=slotstr+days[i].substring(2, days[i].length())+",";
	    				}else if(days[i].substring(0, 2).equals("周五")){
	    					calendar.setTime(date); 
	    					if(weekTimes.equals("两周一次")){
	   	    				     calendar.add(calendar.DATE,addday+5+y*14);//把日期往后增加一天.整数往后推,负数往前移动 
	    					}else{
 	    				     calendar.add(calendar.DATE,addday+5+y*7);//把日期往后增加一天.整数往后推,负数往前移动 
	    					}	
	    				     Date date1=calendar.getTime(); 
		    				     daystr=daystr+ to.format(date1)+",";
		    				     slotstr=slotstr+days[i].substring(2, days[i].length())+",";
	    				}else if(days[i].substring(0, 2).equals("周六")){
	    					calendar.setTime(date); 
	    					if(weekTimes.equals("两周一次")){
	   	    				     calendar.add(calendar.DATE,addday+6+y*14);//把日期往后增加一天.整数往后推,负数往前移动 
	    					}else{
 	    				     calendar.add(calendar.DATE,addday+6+y*7);//把日期往后增加一天.整数往后推,负数往前移动 
	    					}	
	    				     Date date1=calendar.getTime(); 
		    				     daystr=daystr+ to.format(date1)+",";
		    				     slotstr=slotstr+days[i].substring(2, days[i].length())+",";
	    				}else if(days[i].substring(0, 2).equals("周日")){
	    					calendar.setTime(date); 
	    					if(weekTimes.equals("两周一次")){
	   	    				     calendar.add(calendar.DATE,addday+7+y*14);//把日期往后增加一天.整数往后推,负数往前移动 
	    					}else{
 	    				     calendar.add(calendar.DATE,addday+7+y*7);//把日期往后增加一天.整数往后推,负数往前移动 
	    					}	
	    				     Date date1=calendar.getTime(); 
		    				     daystr=daystr+ to.format(date1)+",";
		    				     slotstr=slotstr+days[i].substring(2, days[i].length())+",";
	    				}
	    				
	    			
	    			
	    			}
	    		}
		      
		      
		      return daystr.substring(0, daystr.length()-1)+";"+slotstr+";"+c+";"+b;
		   }
	    public static Date test10(Date current) throws Exception {
	    	Integer currentWeek = Test.getWeekDayNumber(current);  
	        Integer day = days[currentWeek];  
	        System.err.println(currentWeek+"========"+day+"++++++++++");
	        return Test.getDateByDays(current, day);  
	    }
	    private static Integer[] days = { 0, 1, 7, 6, 5, 4, 3, 2 };  

	    public static Date getDateByDays(Date date, int days){  
	        if(date == null) return null;  
	        Calendar calendar = Calendar.getInstance();  
	        calendar.setTime(date);  
	        calendar.set(Calendar.HOUR_OF_DAY, 0);  
	        calendar.set(Calendar.MINUTE, 0);  
	        calendar.set(Calendar.SECOND, 0);  
	        calendar.set(Calendar.MILLISECOND, 0);  
	        calendar.add(Calendar.DAY_OF_MONTH, days);  
	        return calendar.getTime();  
	    }  
	    public static Integer getWeekDayNumber(Date date){  
	        Calendar c = Calendar.getInstance();  
	        c.setTime(date);  
	        return c.get(Calendar.DAY_OF_WEEK);  
	    }  
	   public static String test11(String phoneNumber,String openid,String token){
		   if(phoneNumber!=null&&!phoneNumber.equals("")){
			   System.err.println(phoneNumber);
	       	 UserInfo user= wodeDao.findUserByPhone(phoneNumber);
	       	 
	       	 if(!user.getToken().equals(token)){
	      		  
	       		 	return "TOKEN错误";
	       	 }
	        }else if(openid!=null){
	       	 UserInfo user= wodeDao.findUserByOpenid(openid);
	       	 if(!user.getToken().equals(token)){
	       		 	return "TOKEN错误";
	       	 }
	        }else{
       		 	return "TOKEN错误";
	        }
		return "TOKEN正确";
	    }
}
